//
//  BRRefunedStatusViewController.m
//  BrezzeSaaS
//
//  Created by IOS on 2021/10/13.
//  Copyright © 2021 Brezze GWG. All rights reserved.
//

#import "BRRefunedStatusViewController.h"
#import "BRSupportView.h"

@interface BRRefunedStatusViewController ()

@end

@implementation BRRefunedStatusViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self setUI];
}

#pragma mark - Action --
- (void)btnAction:(UITapGestureRecognizer *)btn {
    
    if (btn.view.tag == 200) {
        [self callPhone];
    }else {
        [self sendEmail:@""];
    }
}

- (void)done:(QMUIButton *)btn {
    
    
    if (self.popType == 1) {
        
        [self.navigationController jk_popToViewControllerWithClassName:@"BRBuyDetailViewController" animated:YES];
        return;
    }
    
    if (self.isHomeBack) {
        [self.navigationController popToRootViewControllerAnimated:YES];
        return;
    }
    
    if (self.typeIn == 2 || self.typeIn == 3) {
        [self.navigationController popToRootViewControllerAnimated:YES];
        return;
    }
    if (self.typeIn == 1) {
        // 返回上上个视图
        NSString *className = self.feedBackInd == 1 ?@"BRFAQDetailViewController":@"BRFAQListViewController";
        [self.navigationController jk_popToViewControllerWithClassName:className animated:YES];
        
        return;
    }
    
    [self pop];
    
}

- (void)callPhone {
    
    [BROpenURL callPhone];
}

- (void)sendEmail:(NSString *)emailStr {
    
    [BROpenURL callEMail];
    
}

#pragma mark - setUI --
- (void)setUI {
    
    [self br_createTop:@"" imageStr:@""];

    UIImageView *defaultImg = [[UIImageView alloc] init];
    defaultImg.image = UIImageMake(@"scan_success");
    [self.view addSubview:defaultImg];
    [defaultImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(28 + kSafeAreaTopHeight);
        make.width.height.mas_equalTo(141);
        make.centerX.equalTo(self.view);
    }];

    NSString *titleStr = Localized(@"help_submitted");
    if (self.typeIn == 0) {
        titleStr = Localized(@"wallet_refundTips");
    }
    if (self.typeIn == 1) {
        titleStr = Localized(@"help_submitted");
    }
    CGFloat title_width = 320.;
    if (self.typeIn == 2) {
        title_width = 256.;
        titleStr = Localized(@"help_submitted");
    }
    QMUILabel *depositL = [BRToolsView br_label:titleStr textColor:kColorMain font:[UIFont fontH:20]];
    depositL.textAlignment = NSTextAlignmentCenter;
    depositL.numberOfLines = 0;
    [self.view addSubview:depositL];
    [depositL mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.width.mas_equalTo(title_width);
        make.left.offset(28);
        make.right.offset(-28);
        make.centerX.equalTo(self.view);
        make.top.equalTo(defaultImg.mas_bottom).offset(4);
    }];
    
    
//
    
    NSString *str = Localized(@"help_thankText");
    if (self.typeIn == 2) {
        str = [NSString stringWithFormat:Localized(@"help_orderFBText"),[BRPayManager br_amount:self.maxAmount]];
    }
    
    QMUILabel *textL = [BRToolsView br_label:str textColor:UIColorMakeWithHex(@"#889DBB") font:[UIFont fontM:14]];
    textL.textAlignment = NSTextAlignmentCenter;
    textL.numberOfLines = 0;
    [self.view addSubview:textL];
    [textL mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.width.mas_equalTo(title_width);
        make.left.offset(28);
        make.right.offset(-28);
        make.centerX.equalTo(self.view);
        make.top.equalTo(depositL.mas_bottom).offset(8);
    }];
    textL.hidden = self.typeIn == 0;
    
    NSString *btnText = self.typeIn == 0 ? Localized(@"public_done") : Localized(@"order_homePage");
    QMUIButton *btn = [BRToolsView br_btnBGImg:btnText];
    [self.view addSubview:btn];
    btn.frame = CGRectMake(14,kScreenHeight - 66 - kSafeAreaBottomHeight, (kScreenWidth - 28), 52);
    [btn addTarget:self action:@selector(done:) forControlEvents:UIControlEventTouchUpInside];
    
    
    
    if (self.typeIn != 0) return; //只有退款成功显示联络视图

    // 支持view 联系视图 退款成功后显示
    UIView *bgView = [[UIView alloc] init];
    bgView.backgroundColor = UIColorClear;
    [self.view addSubview:bgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.height.mas_equalTo(152);
        make.centerX.equalTo(self.view);
        make.bottom.equalTo(self.view.mas_bottom).offset(-(110 + kSafeAreaBottomHeight));
        make.width.mas_equalTo(kScreenWidth - 56);
    }];
    bgView.layer.shadowColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.07].CGColor;
    bgView.layer.shadowOffset = CGSizeMake(0,5);
    bgView.layer.shadowOpacity = 1;
    bgView.layer.shadowRadius = 8;

    UIView *contView  = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth - 56, 152)];
    contView.backgroundColor = UIColor.qd_backgroundColor2;
    [bgView addSubview:contView];
    contView.layer.cornerRadius = kCorners;
    contView.layer.masksToBounds = YES;
    [contView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.offset(0);
    }];

    QMUILabel *helpTextL = [[QMUILabel alloc] init];
    helpTextL.text = Localized(@"help_contactText");
    helpTextL.textColor = UIColor.qd_titleTextColor;
    helpTextL.font = [UIFont br_fontM:17];
    helpTextL.textAlignment = NSTextAlignmentLeft;
    helpTextL.numberOfLines = 0;
    [contView addSubview:helpTextL];
    [helpTextL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(52);
        make.right.top.equalTo(contView);
        make.left.equalTo(contView).offset(28);
    }];

    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 52, contView.mj_w, 0.5)];
    line.backgroundColor = UIColor.qd_lineColor2;
    [contView addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(0.5);
        make.left.equalTo(contView).offset(28);
        make.right.equalTo(contView).offset(-28);
        make.top.offset(52);
    }];

    BRContactView *sView = [[BRContactView alloc] init];
    [contView addSubview:sView];
    [sView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(28);
        make.right.equalTo(contView);
        make.top.equalTo(line.mas_bottom).offset(12);
        make.bottom.equalTo(contView.mas_bottom).offset(-12);
    }];
    sView.stackView.spacing = 12;
    [sView br_hidden:YES by:2];
    sView.br_contactClickBlock = ^(NSInteger index) {

        if (index == 0) {
            [BROpenURL callWhatsapp];
        }else {
            [BROpenURL callEMail];
        }
    };
    
}

- (BOOL)forceEnableInteractivePopGestureRecognizer {
    // 屏蔽右滑返回
    return NO;

}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
